import re

import requests



def get_jigou(id,cookie):
    url = f'{id}/cis/showView.jsp'
    HOST = id.strip("http://")
    headers = {

        "Cookie": f"JSESSIONID={cookie}",
        "Host": HOST,
        "Referer": "http://10.216.11.12:8089/cis/desktop.jsp",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
    }

    res = requests.get(url, headers=headers)
    # 假设 res.text 是包含目标内容的响应文本
    match = re.search(r"json\.hospitalcode\s*=\s*'([^']+)'", res.text)
    if match:
        hospital_code = match.group(1)
        print("提取到的机构码:", hospital_code)
        return hospital_code
    else:
        print("未找到机构码")
        return None




def get_jigou2(id,cookie):
    url = f"{id}/phis/app/index"
    HOST = id.strip("http://")
    headers = {
        "Cookie": f"JSESSIONID={cookie}",
        "Host": HOST,
    }
    res = requests.get(url, headers=headers)
    # 假设 res.text 是包含目标内容的响应文本
    match = re.search(r"orgCode\s*:\s*'(\d\d\d+)'", res.text)
    if match:
        hospital_code = match.group(1)#获取匹配到的内容
        return hospital_code
    else:
        print("未找到机构码")
        return None


if __name__ == '__main__':
    get_jigou("http://10.216.11.12:8089", "1CC554DF90C4720F0BFBD720925E6460")
    get_jigou("http://10.166.140.210:8083", "F9B3A85983251ED68AD0FD992D37969D")